package presenter;


import java.util.Observer;

import bean.login_bean.PersonDataBean;
import interfaces.ILunTanInterface;
import responsitory.LunTanResponsitory;
import util.volley.ICompleteListener;
import util.volley.ResultEntity;

/**
 * 论坛
 */
public class LunTanPresenter extends BasePresenter implements ILunTanInterface<PersonDataBean> {
    //论坛首页
    public static final String indexPage_success = LunTanPresenter.class.getName()
            + "_indexPage_success";
    public static final String indexPage_fail = LunTanPresenter.class.getName()
            + "_indexPage_fail";
    //论坛详情
    public static final String topicDetail_success = LunTanPresenter.class.getName()
            + "_topicDetail_success";
    public static final String topicDetail_fail = LunTanPresenter.class.getName()
            + "_topicDetail_fail";
    //论坛列表
    public static final String topicList_success = LunTanPresenter.class.getName()
            + "_topicList_success";
    public static final String topicList_fail = LunTanPresenter.class.getName()
            + "_topicList_fail";

    //论坛点赞
    public static final String zan_success = LunTanPresenter.class.getName()
            + "_zan_success";
    public static final String zan_fail = LunTanPresenter.class.getName()
            + "_zan_fail";
    //论坛回复列表
    public static final String huifu_success = LunTanPresenter.class.getName()
            + "_huifu_success";
    public static final String huifu_fail = LunTanPresenter.class.getName()
            + "_huifu_fail";
    //论坛回复列表
    public static final String huifu_two_success = LunTanPresenter.class.getName()
            + "_huifu_two_success";
    public static final String huifu_two_fail = LunTanPresenter.class.getName()
            + "_huifu_two_fail";

    //发帖
    public static final String fatie_success = LunTanPresenter.class.getName()
            + "_fatie_success";
    public static final String fatie_fail = LunTanPresenter.class.getName()
            + "_fatie_fail";

    //我的帖子
    public static final String my_tiezi_success = LunTanPresenter.class.getName()
            + "_my_tiezi_success";
    public static final String my_tiezi_fail = LunTanPresenter.class.getName()
            + "_my_tiezi_fail";

    //删除我的帖子
    public static final String delete_tiezi_success = LunTanPresenter.class.getName()
            + "_delete_tiezi_success";
    public static final String delete_tiezi_fail = LunTanPresenter.class.getName()
            + "_delete_tiezi_fail";

    //转发帖子
    public static final String zhuanfa_tiezi_success = LunTanPresenter.class.getName()
            + "_zhuanfa_tiezi_success";
    public static final String zhuanfa_tiezi_fail = LunTanPresenter.class.getName()
            + "_zhuanfa_tiezi_fail";
    //帖子回复
    public static final String huifu_tiezi_success = LunTanPresenter.class.getName()
            + "_huifu_tiezi_success";
    public static final String huifu_tiezi_fail = LunTanPresenter.class.getName()
            + "_huifu_tiezi_fail";

    //签到详情
    public static final String signin_success = LunTanPresenter.class.getName()
            + "_signin_success";
    public static final String signin_fail = LunTanPresenter.class.getName()
            + "_signin_fail";

    //签到动作
    public static final String signinbehive_success = LunTanPresenter.class.getName()
            + "_signinbehive_success";
    public static final String signinbehive_fail = LunTanPresenter.class.getName()
            + "_signinbehive_fail";

    //删除自己的评论
    public static final String delete_pinglun_success = LunTanPresenter.class.getName()
            + "_delete_pinglun_success";
    public static final String delete_pinglun_fail = LunTanPresenter.class.getName()
            + "_delete_pinglun_fail";


    public LunTanPresenter(Observer observer) {
        super(observer);
    }

    @Override
    public void indexPage(int size, String uid) {
        ILunTanInterface<PersonDataBean> user = new LunTanResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(indexPage_success);
                        LunTanPresenter.this.setChanged();
                        LunTanPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(indexPage_fail);
                        LunTanPresenter.this.setChanged();
                        LunTanPresenter.this.notifyObservers(result);

                    }
                });
        user.indexPage(size,uid);
    }

    public void topicDetail(int id, String uid) {
        ILunTanInterface<PersonDataBean> user = new LunTanResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(topicDetail_success);
                        LunTanPresenter.this.setChanged();
                        LunTanPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(topicDetail_fail);
                        LunTanPresenter.this.setChanged();
                        LunTanPresenter.this.notifyObservers(result);

                    }
                });
        user.topicDetail(id,uid);
    }

    @Override
    public void topicList(int page, int size, String uid, String kword) {
        ILunTanInterface<PersonDataBean> user = new LunTanResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(topicList_success);
                        LunTanPresenter.this.setChanged();
                        LunTanPresenter.this.notifyObservers(result);
                    }

                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(topicList_fail);
                        LunTanPresenter.this.setChanged();
                        LunTanPresenter.this.notifyObservers(result);

                    }
                });
        user.topicList(page,size,uid,kword);
    }

    @Override
    public void dianzan(String uid, String pid, String rid) {
        ILunTanInterface<PersonDataBean> user = new LunTanResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(zan_success);
                        LunTanPresenter.this.setChanged();
                        LunTanPresenter.this.notifyObservers(result);
                    }
                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(zan_fail);
                        LunTanPresenter.this.setChanged();
                        LunTanPresenter.this.notifyObservers(result);
                    }
                });
        user.dianzan(uid,pid,rid);
    }

    @Override
    public void topicHuiFuList(String uid, String pid, String rid, int page, int size) {
        ILunTanInterface<PersonDataBean> user = new LunTanResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(huifu_success);
                        LunTanPresenter.this.setChanged();
                        LunTanPresenter.this.notifyObservers(result);
                    }
                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(huifu_fail);
                        LunTanPresenter.this.setChanged();
                        LunTanPresenter.this.notifyObservers(result);
                    }
                });
        user.topicHuiFuList(uid,pid,rid,page,size);
    }

    @Override
    public void topicHuiFuListTwo(String uid, String pid, String rid, int page, int size) {
        ILunTanInterface<PersonDataBean> user = new LunTanResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(huifu_two_success);
                        LunTanPresenter.this.setChanged();
                        LunTanPresenter.this.notifyObservers(result);
                    }
                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(huifu_two_fail);
                        LunTanPresenter.this.setChanged();
                        LunTanPresenter.this.notifyObservers(result);
                    }
                });
        user.topicHuiFuListTwo(uid,pid,rid,page,size);
    }

    @Override
    public void fatie(String uid, String title, String content, String img, String reply_limit, String top, String app) {
        ILunTanInterface<PersonDataBean> user = new LunTanResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(fatie_success);
                        LunTanPresenter.this.setChanged();
                        LunTanPresenter.this.notifyObservers(result);
                    }
                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(fatie_fail);
                        LunTanPresenter.this.setChanged();
                        LunTanPresenter.this.notifyObservers(result);
                    }
                });
        user.fatie(uid,title,content,img,reply_limit,top,app);
    }

    @Override
    public void myTieZi(String uid, int page, int size) {
        ILunTanInterface<PersonDataBean> user = new LunTanResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(my_tiezi_success);
                        LunTanPresenter.this.setChanged();
                        LunTanPresenter.this.notifyObservers(result);
                    }
                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(my_tiezi_fail);
                        LunTanPresenter.this.setChanged();
                        LunTanPresenter.this.notifyObservers(result);
                    }
                });
        user.myTieZi(uid,page,size);
    }

    @Override
    public void deleteTieZi(String uid, String pid) {
        ILunTanInterface<PersonDataBean> user = new LunTanResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(delete_tiezi_success);
                        LunTanPresenter.this.setChanged();
                        LunTanPresenter.this.notifyObservers(result);
                    }
                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(delete_tiezi_fail);
                        LunTanPresenter.this.setChanged();
                        LunTanPresenter.this.notifyObservers(result);
                    }
                });
        user.deleteTieZi(uid,pid);
    }

    @Override
    public void zhuanfaTieZi(String uid, String content, String reply_limit, String repeat_id, String app) {
        ILunTanInterface<PersonDataBean> user = new LunTanResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(zhuanfa_tiezi_success);
                        LunTanPresenter.this.setChanged();
                        LunTanPresenter.this.notifyObservers(result);
                    }
                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(zhuanfa_tiezi_fail);
                        LunTanPresenter.this.setChanged();
                        LunTanPresenter.this.notifyObservers(result);
                    }
                });
        user.zhuanfaTieZi(uid,content,reply_limit,repeat_id,app);
    }

    @Override
    public void huifuTieZi(String uid, String pid, String rid, String to_uid, String content, String img, String app) {
        ILunTanInterface<PersonDataBean> user = new LunTanResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(huifu_tiezi_success);
                        LunTanPresenter.this.setChanged();
                        LunTanPresenter.this.notifyObservers(result);
                    }
                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(huifu_tiezi_fail);
                        LunTanPresenter.this.setChanged();
                        LunTanPresenter.this.notifyObservers(result);
                    }
                });
        user.huifuTieZi(uid,pid,rid,to_uid,content,img,app);
    }


    @Override
    public void SignInShow(String uid) {
        ILunTanInterface<PersonDataBean> user = new LunTanResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(signin_success);
                        LunTanPresenter.this.setChanged();
                        LunTanPresenter.this.notifyObservers(result);
                    }
                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(signin_fail);
                        LunTanPresenter.this.setChanged();
                        LunTanPresenter.this.notifyObservers(result);
                    }
                });
        user.SignInShow(uid);
    }

    @Override
    public void SignIn(String uid) {
        ILunTanInterface<PersonDataBean> user = new LunTanResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(signinbehive_success);
                        LunTanPresenter.this.setChanged();
                        LunTanPresenter.this.notifyObservers(result);
                    }
                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(signinbehive_fail);
                        LunTanPresenter.this.setChanged();
                        LunTanPresenter.this.notifyObservers(result);
                    }
                });
        user.SignIn(uid);
    }
    @Override
    public void deleteMyHuiFu(String uid, int rid) {
        ILunTanInterface<PersonDataBean> user = new LunTanResponsitory(
                new ICompleteListener() {

                    @Override
                    public void success(ResultEntity result) {
                        result.setEventTag(Tag_Success);
                        result.setEventType(delete_pinglun_success);
                        LunTanPresenter.this.setChanged();
                        LunTanPresenter.this.notifyObservers(result);
                    }
                    @Override
                    public void failure(ResultEntity result) {
                        result.setEventTag(Tag_Error);
                        result.setEventType(delete_pinglun_fail);
                        LunTanPresenter.this.setChanged();
                        LunTanPresenter.this.notifyObservers(result);
                    }
                });
        user.deleteMyHuiFu(uid,rid);
    }

}
